package com.alibaba.dubbo.remoting.transport.netty.learn;

import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.RemotingException;

/**
 * @author 作者 E-mail: lgrui1988@163.com
 * @date 创建时间：2017年1月13日 下午3:57:45
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
public class MockUpChannelHandler implements ChannelHandler {
	private static final Logger logger = LoggerFactory.getLogger(MockUpChannelHandler.class);

	public void caught(Channel channel, Throwable exception) throws RemotingException {

	}

	public void connected(Channel channel) throws RemotingException {

	}

	public void disconnected(Channel channel) throws RemotingException {

	}

	public void received(Channel channel, Object message) throws RemotingException {
		MockUpMsg msg = (MockUpMsg) message;
		String strMsg = null;
		try {
			strMsg = new String(msg.getMessage(), "UTF-8");
		} catch (Exception ex) {

		}
		logger.info("Received Msg:" + strMsg);
	}

	public void sent(Channel channel, Object message) throws RemotingException {
		MockUpMsg msg = (MockUpMsg) message;
		String strMsg = null;
		try {
			strMsg = new String(msg.getMessage(), "UTF-8");
		} catch (Exception ex) {

		}
		logger.info("Send Msg:" + strMsg);
	}
}
